// pages/index/hotGoods/hotGoods.js
import {
        list
} from '../../../../api/wxPage'
const util = require('../../../../utils/util')
import {
        list as navigationList
} from '../../../../api/navigation'
let app = getApp();
Component({
        /**
         * 组件的属性列表
         */
        properties: {
                info: {
                        type: Object,
                }
        },
        lifetimes: {
                attached() {
                        var arr = Object.keys(this.data.info.tagids)
                        if (arr.length > 0) {
                                this.data.tagIds = this.data.info.tagids.split(',')
                                for (var i = 0; i < this.data.tagIds.length; i++) {
                                        this.data.tagIds[i] = parseInt(this.data.tagIds[i])
                                }
                                this.setData({
                                        tagIds: this.data.tagIds
                                })
                        }
                        this.loadAd()
                        this.loadnavigation()
                }
        },
        /**
         * 组件的初始数据
         */
        data: {
                navigations: [],
                adList: [],
                pageSize: 2,
                tagIds: [],
                haveThumbnial: false
        },

        /**
         * 组件的方法列表
         */
        methods: {
                topage(e) {
                        // console.info("专题页面被点击了")
                        // console.info(e)
                        wx.navigateTo({
                                url: '/pages/index/wxPage/wxPage?id=' + e.currentTarget.dataset.id
                        })

                },
                toLink(e) {
                        // console.info("导航被点击了")
                        // console.info(e)
                        if (e.currentTarget.dataset.id.typeId) {
                                if (e.currentTarget.dataset.id.type == 1) {
                                        wx.navigateTo({
                                                url: '/pages/goods/category/category?id=' + e.currentTarget.dataset.id.typeId
                                        })
                                }
                                if (e.currentTarget.dataset.id.type == 2) {
                                        wx.navigateTo({
                                                url: '/pages/index/wxPage/wxPage?id=' + e.currentTarget.dataset.id.typeId
                                        })
                                }
                                if (e.currentTarget.dataset.id.type == 3) {
                                        wx.navigateTo({
                                                url: '/pages/goods/product/details?id=' + e.currentTarget.dataset.id.typeId,
                                        })
                                }
                        }
                },
                loadnavigation() {
                        var _this = this;
                        if (this.data.tagIds.length > 0) {
                                navigationList({
                                        mchId: app.globalData.mchId,
                                        tagIds: this.data.tagIds,
                                        pageSize: '2'
                                }).then(res => {
                                        this.data.navigations = res.data.data
                                        console.info("精选榜单111的数据navigations--")
                                        this.data.navigations[0].thumbnial = util.thumbnail(_this.data.navigations[0].thumbnial, 360, 180)
                                        this.data.navigations[1].thumbnial = util.thumbnail(_this.data.navigations[1].thumbnial, 360, 180)
                                        console.info(this.data.navigations)
                                        this.setData({
                                                navigations: this.data.navigations
                                        })
                                })
                        } else {
                                navigationList({
                                        mchId: app.globalData.mchId,
                                        pageSize: '2'
                                }).then(res => {
                                        this.data.navigations = res.data.data
                                        console.info("精选榜单2222的数据navigations--")
                                        console.info(this.data.navigations)
                                        this.data.navigations[0].thumbnial = util.thumbnail(_this.data.navigations[0].thumbnial, 360, 180)
                                        this.data.navigations[1].thumbnial = util.thumbnail(_this.data.navigations[1].thumbnial, 360, 180)
                                        console.info(this.data.navigations)
                                        this.setData({
                                                navigations: this.data.navigations
                                        })
                                })
                        }
                },
                loadAd() {
                        var _this = this;
                        list({
                                mchId: app.globalData.mchId,
                                tagIds: _this.data.tagIds,
                                pageSize: '1'
                        }).then(res => {
                                _this.data.adList = res.data.data
                                let haveThumbnial = _this.data.haveThumbnial
                                if (_this.data.adList.length > 0) {
                                        if (!util.isNull(_this.data.adList[0].thumbnial)) {
                                                _this.data.adList[0].thumbnial = util.thumbnail(_this.data.adList[0].thumbnial, 750, 344)
                                                haveThumbnial = true
                                        }
                                        console.info(_this.data.adList[0].thumbnial)
                                }
                                _this.setData({
                                        adList: _this.data.adList,
                                        haveThumbnial: haveThumbnial
                                })
                        })
                }
        }
})